mastodon_api\methods\admin/
accounts.rs

1use crate::MastodonClient;
2use crate::error::Result;
3
4/// Handler for admin account moderation API endpoints.
5pub struct AdminAccountsHandler<'a> {
6    client: &'a MastodonClient,
7}
8
9impl<'a> AdminAccountsHandler<'a> {
10    pub fn new(client: &'a MastodonClient) -> Self {
11        Self { client }
12    }
13
14    /// Action against an account.
15    pub async fn action(&self, id: &str, r#type: &str) -> Result<()> {
16        let url = format!(
17            "{}/api/v1/admin/accounts/{}/action",
18            self.client.base_url(),
19            id
20        );
21        let req = self
22            .client
23            .http_client()
24            .post(&url)
25            .form(&[("type", r#type)]);
26        self.client.send(req).await
27    }
28
29    /// Suspends an account.
30    pub async fn suspend(&self, id: &str) -> Result<()> {
31        self.action(id, "suspend").await
32    }
33
34    /// Silences an account.
35    pub async fn silence(&self, id: &str) -> Result<()> {
36        self.action(id, "silence").await
37    }
38}